package com.zqh.app.manager.impl;

import com.zqh.app.dao.CountMapper;
import com.zqh.app.entity.Count;
import com.zqh.app.manager.AppCountManager;
import com.zqh.common.entity.Page;
import com.zqh.common.entity.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service("AppCountManager")
public class AppCountManagerImpl implements AppCountManager {

    @Autowired
    CountMapper countMapper;
    @Override
    public List<Count> countTotal(Page<Count> page,Query query) {
        return countMapper.countTotal(page,query);
    }

    @Override
    public List<Count> countTotalDevice(Query query) {
        return countMapper.countTotalDevice(query);
    }

    @Override
    public List<Count> countSex(Query query) {

        return countMapper.countSex(query);
    }

    @Override
    public List<Count> countTotalViscera(Query query) {
        return countMapper.countTotalViscera(query);
    }

    @Override
    public List<Count> countTotalSleep(Query query) {
        return countMapper.countTotalSleep(query);
    }

    @Override
    public List<Count> countTotalSport(Query query) {
        return countMapper.countTotalSport(query);
    }

    @Override
    public List<Count> countTotalLocation(Query query) {
        return countMapper.countTotalLocation(query);
    }

    @Override
    public List<Count> countTotalAge(Query form) {
        return countMapper.countTotalAge(form);
    }

    @Override
    public List<Count> listForPage(Page<Count> page, Query form) {
        return countMapper.listForPage(page,form);
    }

    @Override
    public Count mainCountTotal(Query query) {
        Count count = countMapper.mainCountTotal(query);
        count.setTotalDevice(countMapper.mainCountTotal1(query).getTotalDevice());
        count.setOnlineDevice(countMapper.mainCountTotal2(query).getOnlineDevice());
        return count;
    }

    @Override
    public int saveStatistics(Query query) {
        int count;
        if (countMapper.list(query).isEmpty()){
            count = countMapper.save(query);
        }else {
            count = countMapper.update(query);
        }
        return count;
    }
}
